//
//  KTRegionBtnView.m
//  KTVShopProduct
//
//  Created by paeanSs on 2017/11/8.
//  Copyright © 2017年 paeanSs. All rights reserved.
//

#import "KTRegionBtnView.h"
#import "UIView+BlockGesture.h"

#define SpreadIMG [UIImage imageNamed:@"nav_icon_list"]
#define LeftWidth  15

@interface KTRegionBtnView ()

@property (nonatomic, strong) UILabel *regionLbl;
@property (nonatomic, strong) UIImageView*spreadView;
@property (nonatomic, strong) NSString *regionTitle;

@end

@implementation KTRegionBtnView
- (instancetype)initWithTitle:(NSString *)title{
    if (self = [super init]) {
        self.regionTitle = title;
        [self setupSubViews];
    }
    return self;

}

- (void)setupSubViews{
    self.regionLbl = [[UILabel alloc] init];
    self.regionLbl.font = [UIFont systemFontOfSize:15];
    self.regionLbl.textAlignment = NSTextAlignmentLeft;
    self.regionLbl.textColor = [UIColor blackColor];
    [self.regionLbl sizeToFit];
    [self addSubview:self.regionLbl];
    self.regionLbl.text = self.regionTitle;
    
    [self.regionLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(self.regionLbl);
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(LeftWidth);
    }];
    
    self.spreadView = [[UIImageView alloc] initWithImage:SpreadIMG];
    [self addSubview:self.spreadView];
    
    [self.spreadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(SpreadIMG.size);
        make.centerY.right.equalTo(self);
    }];
}

- (void)setTitle:(NSString *)title withSuperView:(UIView *)superView{
    self.regionTitle = title;
    self.regionLbl.text = title;
    CGFloat leftWidth = 15;
    CGFloat selfWidth = [KTTool widthOfString:title font:[UIFont systemFontOfSize:15] height:44.0] + SpreadIMG.size.width + 5 + leftWidth;
    [self mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(selfWidth, 44.0));
        make.left.equalTo(superView);
        make.top.equalTo(superView).offset(64);
    }];
}

@end
